package com.zhsj.OkeHomeConsumption.ui.activity.wallet;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.empty.WalletBean;

import java.util.List;

/**
 * Created by zwj on 2018/3/12.
 */

public class WalletDetailAdapter extends BaseAdapter {

    private Context context;
    private List<WalletBean> list;
    private LayoutInflater mLayoutInflater;

    public WalletDetailAdapter(Context context, List<WalletBean> walletList) {
        this.context = context;
        this.list = walletList;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_money_detail, null);
            viewHolder.name_text = (TextView) convertView.findViewById(R.id.name_text);
            viewHolder.money_text = (TextView) convertView.findViewById(R.id.money_text);
            viewHolder.time_text = (TextView) convertView.findViewById(R.id.time_text);
            viewHolder.type_text = (TextView) convertView.findViewById(R.id.type_text);
            viewHolder.number_text = (TextView) convertView.findViewById(R.id.number_text);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        final WalletBean item = list.get(position);

        if (item != null) {
            viewHolder.name_text.setText(item.getBusiPartnerName());
            if ("提现手续费".equals(item.getBusiPartnerName()) || "提现".equals(item.getBusiPartnerName())){
                viewHolder.money_text.setText("-" + item.getMoneyOrder());
                viewHolder.money_text.setTextColor(context.getResources().getColor(R.color.blue_text));
            }else {
                viewHolder.money_text.setText("+" + item.getMoneyOrder());
                viewHolder.money_text.setTextColor(context.getResources().getColor(R.color.yellow_text));
            }
            viewHolder.time_text.setText(item.getCreateTime());
            if (item.getBusiPartnerName().indexOf("佣金") != -1 ){
                viewHolder.type_text.setText("项目编号:");
                viewHolder.number_text.setText(item.getNum());
            }else {
                viewHolder.type_text.setText("流水号:");
                viewHolder.number_text.setText(item.getNoOrder());
            }
        }
        return convertView;
    }


    class ViewHolder {
        private TextView name_text;
        private TextView money_text;
        private TextView time_text;
        private TextView type_text;
        private TextView number_text;
    }


}
